#include"process.h"
#define LENGTH 101
#define LABLE '#'

void FlushProcess(double target, double current)
{
    //step1:光标
    const static char* symp="|/-\\";
    int static index=0;
    int len=strlen(symp);
    //step2:占比计算
    double rate=(current/target)*100.0;
    //step3:精度条递增'#'的个数
    int cnt=(int)rate;
    char buf[LENGTH];
    memset(buf,0,sizeof(buf));
    for(int i=0;i<cnt;i++)
        buf[i]=LABLE;
    printf("[%-100s][%.1lf%%][%c]\r",buf,rate,symp[index++]);
    index%=len;
    fflush(stdout);
}

void process()
{
    const char* symp="|/-\\";
    char buf[LENGTH];
    memset(buf,'\0',sizeof(buf));
    int cnt=0;
    while(cnt<=100)
    {
        printf("[%-100s][%2d%%][%c]\r",buf,cnt,symp[cnt%4]);
        fflush(stdout);
        usleep(50000);
        buf[cnt++]=LABLE;

    }
    printf("\n");
}
